﻿Global.namespace("System.Web.MasterPage");
System.Web.MasterPage.Default=function(config){
    // html of template
    config.templateFile='DefaultMasterPage.htm?t='+ Global.random();
    
    System.Web.MasterPage.Default.superclass.constructor.call(this,config);
}
Global.extend(System.Web.MasterPage.Default,System.Core.UI.BaseMasterPage,{
    tempalte:'<div class="MasterPageWrapper"></div>',
    onLoading:function(){
        Global.showLoadingMask({
            wrapper:'#'+this.id,
            id:'home_Loading'
        });
        logger.info('onLoading of Default amsterpage');
    },
    onRendered:function(){
        //return;
        var ctr=this;
        System.Web.Handler.RequestHandler.getOwner(function(data){
            ctr.loadDefaulPage(data.getField(opensocial.Person.Field.ID));
            
        });
        
    },
    loadDefaulPage:function(ownerId){
        var ctr=this;
        var url=StringHandler.format(
            "{0}inlineservice.axd?action=CheckExist&userId={1}&t={2}",
            Config.rootServiceURL,
            ownerId,
            Global.random()
        ); 
        
        System.Core.Handler.RequestHandler.get(
            url,
            {},
            function(reponse){
                var data=StringHandler.format(
                    "({0})", 
                    System.Core.Handler.RequestHandler.getResponseData(reponse)
                );
                
                var result=eval(data);
                if(result.isExist===false){    
                    ctr.loadControl(System.Web.Page.Register, { wrapper: '.MasterPageWrapper',autoRender:true,userId:ownerId });
                    return;
                }
                System.Web.Runtime.currentUser=result;
                ctr.loadControl(System.Web.Page.Home, { wrapper: '.MasterPageWrapper',autoRender:true });
            }
        );
    }
});